﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using IsikFx.Project.ClientApp.Helpers;
using IsikFx.Project.CommonTypes;

namespace IsikFx.Project.ClientApp.Content
{
    /// <summary>
    /// Interaction logic for GoalInfo.xaml
    /// </summary>
    public partial class GoalInfo : UserControl
    {
        Goals goals;
        public GoalInfo()
        {
            InitializeComponent();
            this.DataContext = null;
            Loaded += GoalInfo_Loaded;
        }

        void GoalInfo_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                Goal goal = Helpers.Helper.GetAgentGoal();
                GoalProgress progress = Helpers.Helper.GetGoalProgress();
                if (progress != null)
                {
                    goals = new Goals();

                    goals.FundAccountGoal = goal.AccountGoal.ToString();
                    goals.FundAccountProgress = progress.AccountCount.ToString();
                    goals.FundAccountGoalPercantage = goal.AccountGoal != 0 ? String.Format(Helper.GoalBarFormat, ((100 * progress.AccountCount) / goal.AccountGoal), progress.AccountCount, goal.AccountGoal) : String.Format(Helper.GoalBarFormat, 0, 0, 0);

                    goals.FundAmountGoal = goal.FundGoal.ToString();
                    goals.FundAmountProgress = progress.TotalFundAmount.ToString();
                    goals.FundAmountGoalPercantage = goal.FundGoal != 0 ? String.Format(String.Format(Helper.GoalBarFormat, ((100 * progress.TotalFundAmount) / goal.FundGoal), progress.TotalFundAmount, goal.FundGoal)) : String.Format(String.Format(Helper.GoalBarFormat, 0, 0, 0));
                    this.DataContext = goals;
                }
            }
            catch (Exception ex)
            {
                Helper.ShowMessage("İşlem gerçekleştirilemiyor, daha sonra tekrar deneyiniz.");
            }
        }
    }


    public class Goals
    {
        public string FundAccountGoal { get; set; }
        public string FundAccountProgress { get; set; }
        public string FundAccountGoalPercantage { get; set; }

        public string FundAmountGoal { get; set; }
        public string FundAmountProgress { get; set; }
        public string FundAmountGoalPercantage { get; set; }
    }
}
